package com.guo.worktool.manager;


import com.guo.worktool.config.TaskThreadPool;
import com.guo.worktool.utils.Threads;
import java.util.concurrent.ExecutorService;

/**
 * 异步任务管理器
 */
public class AsyncManager {



    private ExecutorService executor = TaskThreadPool.getThreadPool();


    /**
     * 单例模式
     */
    private AsyncManager() {
    }

    private static AsyncManager me = new AsyncManager();

    public static AsyncManager me() {
        return me;
    }

    /**
     * 执行任务
     *
     * @param task 任务
     */
    public void execute(Runnable task) {
        executor.execute(task);
    }

    public void submit(Runnable task){
        executor.submit(task);
    }

    /**
     * 停止任务线程池
     */
    public void shutdown() {
        Threads.shutdownAndAwaitTermination(executor);
    }
}
